version 8.0 
log using legislative.log, replace
 #delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      legislative.do                                  *;
*       Date:           1/22/05                                         *;
*       Author:         MRG                                             *;
*       Purpose:        Do-file to replicate results for CPS version    *;
*                       of the number of parties paper where dependent  *;
*                       variable is legislative parties.                *;  
*       Input File:     legislative_new.dta                             *;
*       Output File:    legislative.log                                 *;
*       Data Output:    None                                            *;
*       Previous file:                                                  *;
*       Machine:        Office                                          *;
*     ****************************************************************  *;
*     ****************************************************************  *;

set mem 10m;
set matsize 150;

use "C:\Documents and Settings\Matt Golder\My Documents\fsu\publications\cps2\legislative_new.dta", clear;

*     ****************************************************************  *;
*                           Summary Statistics                          *;
*     ****************************************************************  *;

sum;

*     ****************************************************************  *;
*                    Relabel and Define Variables                       *;
*     ****************************************************************  *;

label var country  "countryname";
label var newdem "first election as new democracy";
label var countrynumber "countrynumber";
label var year "year";
label var regime "regime as of 31 December of given year 0=democracy 1=dictatorship";
label var regime_leg "regime type at time of legislative election 0 = democracy 1=dictatorship";
label var legelec "legislative election";
label var preselec "presidential election";
label var eighties "election in 1980s closest to 1985";
label var old "elections in countries that did not transition to democracy in 1990s";
label var nineties "elections in 1990s closest to 1995";
label var proximity1 "proximity - continuous";
label var proximity2 "proximity - dichotomous";
label var enpp "parliamentary parties - uncorrected";
label var enpp1 "parliamentary parties - corrected";
label var enep "electoral parties - uncorrected";
label var enep1 "electoral parties - corrected";
label var enpres "effective number of presidential candidates";
label var seats "assembly size";
label var districts "number of electoral districts";
label var avemag "average district magnitude";
label var medmag "median district magnitude";
label var upperseats "number of uppertier seats";
label var uppertier "percentage of uppertier seats";
label var eneg "effective number of ethnic groups  fearon";

describe;

*     ****************************************************************  *;
*       Need to drop countries that have no formal parties              *;
*       since I am interested in determining the number of parties.     *;
*       Drop Kiribati, Marshall Islands, Micronesia, Nauru, Palau,      *;
*       Lebanon (at least no votes by party), Kyrgzstan.                *;
*       Since I am interested in competitive elections I drop the       *;
*       elections that occurred in Colombia between 1958 and 1970 due   *;
*       to a constitutional agreement to share power between the        *;
*       conservative and liberal parties.                               *;
*       Also drop the Congolese elections of 1963.  Although there were *;
*       multiple parties permitted, all candidates ran on a single list.*;
*       Thus, there was no actual competition in this election.         *;
*     ****************************************************************  *;

drop if countrynumber==163;
drop if countrynumber==165;
drop if countrynumber==197;
drop if countrynumber==189;
drop if countrynumber==146;
drop if countrynumber==198;
drop if countrynumber==167;
drop if countrynumber==70 & year==1958;
drop if countrynumber==70 & year==1960;
drop if countrynumber==70 & year==1962;
drop if countrynumber==70 & year==1964;
drop if countrynumber==70 & year==1966;
drop if countrynumber==70 & year==1968;
drop if countrynumber==70 & year==1970;
drop if countrynumber==12 & year==1963;

sum;

*     ****************************************************************  *;
*       Does it matter if I use avemag instead of medmag?               *;
*     ****************************************************************  *;

correlate avemag medmag;
correlate avemag medmag if avemag~=1;

*     ****************************************************************  *;
*       Correlation is extremely high in both cases i.e. greater than   *;
*       99%.                                                            *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Generate interaction variables ready for regressions.           *;
*     ****************************************************************  *;

generate logmag=ln(avemag);
generate enep_logmag = enep1*logmag;
generate enep_uppertier = enep1*uppertier;

*     ****************************************************************  *;
*           Now drop countries with majoritarian uppertiers             *;
*     ****************************************************************  *;

drop if countrynumber==132;
drop if countrynumber==29;
drop if countrynumber==87 & year==1988;
drop if countrynumber==87 & year==1992;
drop if countrynumber==87 & year==1996;
drop if countrynumber==116 & year==1987;
drop if countrynumber==116 & year==1996;

*     ****************************************************************  *;
*       Drop those countries where enep1 or enpp1 others are greater    *;
*       than 15% of the vote or seats. Lose 32 observations             *;
*     ****************************************************************  *;

list country year if enep_others>15 & enep_others<100;

list country year if enpp_others>15 & enpp_others<100;

drop if enep_others>15 & enep_others<100;

drop if enpp_others>15 & enpp_others<100;

sum;

*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*        So, now let's run stuff- Here are results for Table 1          *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*                 Run model for the 1990s our data                      *;
*     ****************************************************************  *;

regress enpp1 enep1 logmag enep_logmag uppertier enep_uppertier if nineties==1;

*     ****************************************************************  *;
*      Run model for the 1990s established democracies only - our data  *;
*     ****************************************************************  *;

regress enpp1 enep1 logmag enep_logmag uppertier enep_uppertier if nineties==1 & old==1;

*     ****************************************************************  *;
*                           Pooled analysis                             *;
*     ****************************************************************  *;

regress enpp1 enep1 logmag enep_logmag uppertier enep_uppertier, robust cluster(country);

*     ****************************************************************  *;
*                   Pooled analysis - established democracies           *;
*     ****************************************************************  *;

regress enpp1 enep1 logmag enep_logmag uppertier enep_uppertier if old==1, robust cluster(country);


*     ****************************************************************  *;
*       So, we have replicated all of the results in Table 1 of the     *;
*       article.                                                        *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Need to show how I calculated standard errors and confidence    *;
*       intervals for marginal effect of electoral parties.             *;
*       The marginal effect of electoral parties when UppertierSeats=0  *;
*       and ln(magnitude)=0 is 0.63 [0.52, 0.74].                       *;
*       The marginal effect of electoral parties when UppertierSeats=0  *;
*       and ln(magnitude)=4.79 is 0.90 [0.81, 0.99].                    *;
*     ****************************************************************  *;

regress enpp1 enep1 logmag enep_logmag uppertier enep_uppertier if old==1, robust cluster(country);

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b3=b[1,3];
scalar varb1=V[1,1];
scalar varb3=V[3,3];
scalar covb1b3=V[1,3];

gen conb=b1+b3*4.79;
display conb;

gen conse=sqrt(varb1+varb3*4.79^2+2*covb1b3*4.79);
display conse;

gen a=1.96*conse;
gen top=conb+a;
gen bottom=conb-a;
display top bottom;

drop conb conse a top bottom;

 
*     ****************************************************************  *;
*          Now time to do panel analysis with xtpcse                    *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       First, I need to drop one election from those countries that    *;
*       have two elections in the same year because we can't have       *;
*       repeated time values within panel. Drops 18 observations.       *;
*     ****************************************************************  *;

replace year=. if twoelections1==1;

sum;

*     ****************************************************************  *;
*       Now I need to tsset the data.                                   *;
*     ****************************************************************  *;

tsset countrynumber year, yearly;

*     ****************************************************************  *;
*                         XTPCSE                                        *;
*     ****************************************************************  *;

xtpcse enpp1 enep1 logmag enep_logmag uppertier enep_uppertier, pairwise;

*     ****************************************************************  *;
*               XTPCSE - established democracies only                   *;
*     ****************************************************************  *;

xtpcse enpp1 enep1 logmag enep_logmag uppertier enep_uppertier if old==1, pairwise;


*     ****************************************************************  *;
*       Need to show how I calculated standard errors and confidence    *;
*       intervals for marginal effect of electoral parties.             *;
*       The marginal effect of electoral parties when UppertierSeats=0  *;
*       and ln(magnitude)=0 is 0.63 [0.58, 0.67].                       *;
*       The marginal effect of electoral parties when UppertierSeats=0  *;
*       and ln(magnitude)=5.01 is 0.92 [0.85, 0.98].                    *;
*     ****************************************************************  *;

xtpcse enpp1 enep1 logmag enep_logmag uppertier enep_uppertier if old==1, pairwise;

matrix b=e(b);
matrix V=e(V);
scalar b1=b[1,1];
scalar b3=b[1,3];
scalar varb1=V[1,1];
scalar varb3=V[3,3];
scalar covb1b3=V[1,3];

gen conb=b1+b3*5.01;
display conb;

gen conse=sqrt(varb1+varb3*5.01^2+2*covb1b3*5.01);
display conse;

gen a=1.96*conse;
gen top=conb+a;
gen bottom=conb-a;
display top bottom;
              
*     ****************************************************************  *;
*     ****************************************************************  *;
*                                   THE END                             *;
*     ****************************************************************  *;
*     ****************************************************************  *;



exit;
